// <copyright file="TabItem.cs" company="YUIAsp.Net">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>raul popescu</author>
// <email>dev@yuiasp.net</email>
// <date>2009-01-30</date>
// <summary>YUIAsp.Net File</summary>

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YUIAspNet
{
    /// <summary>
    /// Represents an item in the TabPanel.
    /// </summary>
    [ToolboxItem(false)]
    [ParseChildren(true)]
    public class TabItem : Panel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TabItem"/> class.
        /// </summary>
        public TabItem()
        {
            this.Init += new System.EventHandler(TabItem_Init);
        }

        void TabItem_Init(object sender, System.EventArgs e)
        {
            EnsureChildControls();
        }

        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            if (ContentTemplate != null)
            {
                Control c = new Control();
                ContentTemplate.InstantiateIn(c);
                Controls.Add(c);
            }
            
            base.CreateChildControls();
        }

        /// <summary>
        /// Gets or sets the content template.
        /// </summary>
        /// <value>The content template.</value>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [TemplateInstance(TemplateInstance.Single)]
        [Browsable(false)]
        [MergableProperty(false)]
        public ITemplate ContentTemplate { get; set; }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        /// <value>The text.</value>
        public string Text { get; set; }

        /// <summary>
        /// Gets or sets the content.
        /// </summary>
        /// <value>The content.</value>
        public string Content { get; set; }

        /// <summary>
        /// Gets or sets the content URL.
        /// </summary>
        /// <value>The content URL.</value>
        public Uri ContentUrl { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="TabItem"/> is active.
        /// </summary>
        /// <value><c>true</c> if active; otherwise, <c>false</c>.</value>
        public bool Active { get; set; }
    }
}
